﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using AimGameLibrary;
using AimGameEngine.EditorObject;

namespace AimGameEngine.NodeEditorObject
{
    public class NodeDrawSprite : NodeBaseControl
    {
        public String nodetexture2d = "NULL";
        public String nodevector2 = "NULL";
        public String noderectangle = "NULL";
        public String nodecolor = "NULL";
        public String noderotation = "NULL";
        public String nodeorigin = "NULL";
        public String nodescale = "NULL";
        public String nodespriteeffect = "NULL";
        public String nodedepth = "NULL";

        public NodeDrawSprite(SpriteBatch inputspritebatch, Camera inputcamera, NodeData inputData
            , List<IDraw> MyListDraw, List<IUpdateMainTime> MyListUpdateTime, Dictionary<String, NodeObject> MyListObject, Dictionary<String, NodeObject> MyListType)
            : base(inputspritebatch, inputcamera, inputData, MyListDraw,MyListUpdateTime, MyListObject, MyListType)
        {
            Connecter InputTexture = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Texture2D, this);
            ListConnectpoint.Add(InputTexture);

            Connecter InputPosition = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Vector2, this);
            ListConnectpoint.Add(InputPosition);

            Connecter InputSource = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Rectangle, this);
            ListConnectpoint.Add(InputSource);

            Connecter InputColor = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Color, this);
            ListConnectpoint.Add(InputColor);

            Connecter InputRotation = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Float, this);
            ListConnectpoint.Add(InputRotation);

            Connecter InputOrigin = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Vector2, this);
            ListConnectpoint.Add(InputOrigin);

            Connecter InputScale = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Vector2, this);
            ListConnectpoint.Add(InputScale);

            Connecter InputSpriteEffect = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.SpriteEffects, this);
            ListConnectpoint.Add(InputSpriteEffect);

            Connecter InputDepth = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Float, this);
            ListConnectpoint.Add(InputDepth);

            Connecter OutputDraw = new Connecter(inputspritebatch, inputcamera, Syco.Output, NodeTypeValue.Draw, this);
            ListConnectpoint.Add(OutputDraw);
        }

        public override void SetupInput(Connecter Thisconnect, Connecter connectOutput)
        {
            switch (ListConnectpointInput.IndexOf(Thisconnect))
                {
                    case 0: nodetexture2d = connectOutput.MyNode.MyData.MyName; break;
                    case 1: nodevector2 = connectOutput.MyNode.MyData.MyName; break;
                    case 2: noderectangle = connectOutput.MyNode.MyData.MyName; break;
                    case 3: nodecolor = connectOutput.MyNode.MyData.MyName; break;
                    case 4: noderotation = connectOutput.MyNode.MyData.MyName; break;
                    case 5: nodeorigin = connectOutput.MyNode.MyData.MyName; break;
                    case 6: nodescale = connectOutput.MyNode.MyData.MyName; break;
                    case 7: nodespriteeffect = connectOutput.MyNode.MyData.MyName; break;
                    case 8: nodedepth = connectOutput.MyNode.MyData.MyName; break;
                }
            MyData.Data = nodetexture2d + "|" + nodevector2 + "|" + noderectangle + "|" + nodecolor + "|" + noderotation + "|" + nodeorigin + "|" + nodescale + "|" + nodespriteeffect + "|" + nodedepth;
        }

        public override void ClearInput(Connecter ThisInputConnect, Connecter ThisConnectClear, string NameThisClear)
        {
            MyData.Data = MyData.Data.Replace(NameThisClear, "NULL");
        }

        protected override Dictionary<string, NodeObject> GetDictionaryNode(Dictionary<string, NodeObject> TempNode)
        {
            if(nodetexture2d != null)
            if (this.MyDictionaryObject.ContainsKey(nodetexture2d))
                TempNode.Add(nodetexture2d, this.MyDictionaryObject[nodetexture2d]);
            
            if(nodevector2!=null)
            if (this.MyDictionaryObject.ContainsKey(nodevector2))
                TempNode.Add(nodevector2, this.MyDictionaryObject[nodevector2]);

            if(noderectangle != null)
            if (this.MyDictionaryObject.ContainsKey(noderectangle))
                TempNode.Add(noderectangle, this.MyDictionaryObject[noderectangle]);

            if (nodecolor != null)
                if (this.MyDictionaryObject.ContainsKey(nodecolor))
                    TempNode.Add(nodecolor, this.MyDictionaryObject[nodecolor]);

            if (noderotation != null)
                if (this.MyDictionaryObject.ContainsKey(noderotation))
                    TempNode.Add(noderotation, this.MyDictionaryObject[noderotation]);

            if (nodeorigin != null)
                if (this.MyDictionaryObject.ContainsKey(nodeorigin))
                    TempNode.Add(nodeorigin, this.MyDictionaryObject[nodeorigin]);

            if (nodescale != null)
                if (this.MyDictionaryObject.ContainsKey(nodescale))
                    TempNode.Add(nodescale, this.MyDictionaryObject[nodescale]);

            if (nodespriteeffect != null)
                if (this.MyDictionaryObject.ContainsKey(nodespriteeffect))
                    TempNode.Add(nodespriteeffect, this.MyDictionaryObject[nodespriteeffect]);

            if (nodedepth != null)
                if (this.MyDictionaryObject.ContainsKey(nodedepth))
                    TempNode.Add(nodedepth, this.MyDictionaryObject[nodedepth]);

            return base.GetDictionaryNode(TempNode);
        }

    }
}
